﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ExpressionUtil.Parser.Handler
{
    /// <summary>
    /// 解析处理程序基类
    /// </summary>
    internal abstract class ParseHandlerBase : IParseHandler
    {
        /// <summary>
        /// 下一解析处理程序
        /// </summary>
        protected IParseHandler next;

        /// <summary>
        /// 解析元素
        /// </summary>
        /// <param name="context">解析参数</param>
        /// <param name="element">需要解析的元素</param>
        /// <returns>是否已解析</returns>
        public bool ParseElement(string element, ParseContext context)
        {
            bool ret = this.ParseCore(element,context);
            if(!ret)
            {
                ret = this.next.ParseElement(element, context);
            }
            return ret;
        }

        /// <summary>
        /// 解析元素
        /// </summary>
        /// <param name="context">解析参数</param>
        /// <param name="element">需要解析的元素</param>
        /// <returns>是否已解析</returns>
        protected abstract bool ParseCore(string element, ParseContext context);
    }
}
